/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
/**
 * Autogenerated by Thrift Compiler (0.15.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package org.apache.pinot.common.request;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2024-05-01")
public class BrokerRequest implements org.apache.thrift.TBase<BrokerRequest, BrokerRequest._Fields>, java.io.Serializable, Cloneable, Comparable<BrokerRequest> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("BrokerRequest");

  private static final org.apache.thrift.protocol.TField QUERY_SOURCE_FIELD_DESC = new org.apache.thrift.protocol.TField("querySource", org.apache.thrift.protocol.TType.STRUCT, (short)2);
  private static final org.apache.thrift.protocol.TField PINOT_QUERY_FIELD_DESC = new org.apache.thrift.protocol.TField("pinotQuery", org.apache.thrift.protocol.TType.STRUCT, (short)17);

  private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new BrokerRequestStandardSchemeFactory();
  private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new BrokerRequestTupleSchemeFactory();

  private @org.apache.thrift.annotation.Nullable QuerySource querySource; // optional
  private @org.apache.thrift.annotation.Nullable org.apache.pinot.common.request.PinotQuery pinotQuery; // optional

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    QUERY_SOURCE((short)2, "querySource"),
    PINOT_QUERY((short)17, "pinotQuery");

    private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();

    static {
      for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    @org.apache.thrift.annotation.Nullable
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 2: // QUERY_SOURCE
          return QUERY_SOURCE;
        case 17: // PINOT_QUERY
          return PINOT_QUERY;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    @org.apache.thrift.annotation.Nullable
    public static _Fields findByName(java.lang.String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final java.lang.String _fieldName;

    _Fields(short thriftId, java.lang.String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public java.lang.String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  private static final _Fields optionals[] = {_Fields.QUERY_SOURCE,_Fields.PINOT_QUERY};
  public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.QUERY_SOURCE, new org.apache.thrift.meta_data.FieldMetaData("querySource", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, QuerySource.class)));
    tmpMap.put(_Fields.PINOT_QUERY, new org.apache.thrift.meta_data.FieldMetaData("pinotQuery", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.apache.pinot.common.request.PinotQuery.class)));
    metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(BrokerRequest.class, metaDataMap);
  }

  public BrokerRequest() {
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public BrokerRequest(BrokerRequest other) {
    if (other.isSetQuerySource()) {
      this.querySource = new QuerySource(other.querySource);
    }
    if (other.isSetPinotQuery()) {
      this.pinotQuery = new org.apache.pinot.common.request.PinotQuery(other.pinotQuery);
    }
  }

  public BrokerRequest deepCopy() {
    return new BrokerRequest(this);
  }

  @Override
  public void clear() {
    this.querySource = null;
    this.pinotQuery = null;
  }

  @org.apache.thrift.annotation.Nullable
  public QuerySource getQuerySource() {
    return this.querySource;
  }

  public void setQuerySource(@org.apache.thrift.annotation.Nullable QuerySource querySource) {
    this.querySource = querySource;
  }

  public void unsetQuerySource() {
    this.querySource = null;
  }

  /** Returns true if field querySource is set (has been assigned a value) and false otherwise */
  public boolean isSetQuerySource() {
    return this.querySource != null;
  }

  public void setQuerySourceIsSet(boolean value) {
    if (!value) {
      this.querySource = null;
    }
  }

  @org.apache.thrift.annotation.Nullable
  public org.apache.pinot.common.request.PinotQuery getPinotQuery() {
    return this.pinotQuery;
  }

  public void setPinotQuery(@org.apache.thrift.annotation.Nullable org.apache.pinot.common.request.PinotQuery pinotQuery) {
    this.pinotQuery = pinotQuery;
  }

  public void unsetPinotQuery() {
    this.pinotQuery = null;
  }

  /** Returns true if field pinotQuery is set (has been assigned a value) and false otherwise */
  public boolean isSetPinotQuery() {
    return this.pinotQuery != null;
  }

  public void setPinotQueryIsSet(boolean value) {
    if (!value) {
      this.pinotQuery = null;
    }
  }

  public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
    switch (field) {
    case QUERY_SOURCE:
      if (value == null) {
        unsetQuerySource();
      } else {
        setQuerySource((QuerySource)value);
      }
      break;

    case PINOT_QUERY:
      if (value == null) {
        unsetPinotQuery();
      } else {
        setPinotQuery((org.apache.pinot.common.request.PinotQuery)value);
      }
      break;

    }
  }

  @org.apache.thrift.annotation.Nullable
  public java.lang.Object getFieldValue(_Fields field) {
    switch (field) {
    case QUERY_SOURCE:
      return getQuerySource();

    case PINOT_QUERY:
      return getPinotQuery();

    }
    throw new java.lang.IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new java.lang.IllegalArgumentException();
    }

    switch (field) {
    case QUERY_SOURCE:
      return isSetQuerySource();
    case PINOT_QUERY:
      return isSetPinotQuery();
    }
    throw new java.lang.IllegalStateException();
  }

  @Override
  public boolean equals(java.lang.Object that) {
    if (that instanceof BrokerRequest)
      return this.equals((BrokerRequest)that);
    return false;
  }

  public boolean equals(BrokerRequest that) {
    if (that == null)
      return false;
    if (this == that)
      return true;

    boolean this_present_querySource = true && this.isSetQuerySource();
    boolean that_present_querySource = true && that.isSetQuerySource();
    if (this_present_querySource || that_present_querySource) {
      if (!(this_present_querySource && that_present_querySource))
        return false;
      if (!this.querySource.equals(that.querySource))
        return false;
    }

    boolean this_present_pinotQuery = true && this.isSetPinotQuery();
    boolean that_present_pinotQuery = true && that.isSetPinotQuery();
    if (this_present_pinotQuery || that_present_pinotQuery) {
      if (!(this_present_pinotQuery && that_present_pinotQuery))
        return false;
      if (!this.pinotQuery.equals(that.pinotQuery))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int hashCode = 1;

    hashCode = hashCode * 8191 + ((isSetQuerySource()) ? 131071 : 524287);
    if (isSetQuerySource())
      hashCode = hashCode * 8191 + querySource.hashCode();

    hashCode = hashCode * 8191 + ((isSetPinotQuery()) ? 131071 : 524287);
    if (isSetPinotQuery())
      hashCode = hashCode * 8191 + pinotQuery.hashCode();

    return hashCode;
  }

  @Override
  public int compareTo(BrokerRequest other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = java.lang.Boolean.compare(isSetQuerySource(), other.isSetQuerySource());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetQuerySource()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.querySource, other.querySource);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = java.lang.Boolean.compare(isSetPinotQuery(), other.isSetPinotQuery());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPinotQuery()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.pinotQuery, other.pinotQuery);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  @org.apache.thrift.annotation.Nullable
  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    scheme(iprot).read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    scheme(oprot).write(oprot, this);
  }

  @Override
  public java.lang.String toString() {
    java.lang.StringBuilder sb = new java.lang.StringBuilder("BrokerRequest(");
    boolean first = true;

    if (isSetQuerySource()) {
      sb.append("querySource:");
      if (this.querySource == null) {
        sb.append("null");
      } else {
        sb.append(this.querySource);
      }
      first = false;
    }
    if (isSetPinotQuery()) {
      if (!first) sb.append(", ");
      sb.append("pinotQuery:");
      if (this.pinotQuery == null) {
        sb.append("null");
      } else {
        sb.append(this.pinotQuery);
      }
      first = false;
    }
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
    if (querySource != null) {
      querySource.validate();
    }
    if (pinotQuery != null) {
      pinotQuery.validate();
    }
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
    try {
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class BrokerRequestStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
    public BrokerRequestStandardScheme getScheme() {
      return new BrokerRequestStandardScheme();
    }
  }

  private static class BrokerRequestStandardScheme extends org.apache.thrift.scheme.StandardScheme<BrokerRequest> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, BrokerRequest struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 2: // QUERY_SOURCE
            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
              struct.querySource = new QuerySource();
              struct.querySource.read(iprot);
              struct.setQuerySourceIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 17: // PINOT_QUERY
            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
              struct.pinotQuery = new org.apache.pinot.common.request.PinotQuery();
              struct.pinotQuery.read(iprot);
              struct.setPinotQueryIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, BrokerRequest struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.querySource != null) {
        if (struct.isSetQuerySource()) {
          oprot.writeFieldBegin(QUERY_SOURCE_FIELD_DESC);
          struct.querySource.write(oprot);
          oprot.writeFieldEnd();
        }
      }
      if (struct.pinotQuery != null) {
        if (struct.isSetPinotQuery()) {
          oprot.writeFieldBegin(PINOT_QUERY_FIELD_DESC);
          struct.pinotQuery.write(oprot);
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class BrokerRequestTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
    public BrokerRequestTupleScheme getScheme() {
      return new BrokerRequestTupleScheme();
    }
  }

  private static class BrokerRequestTupleScheme extends org.apache.thrift.scheme.TupleScheme<BrokerRequest> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, BrokerRequest struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
      java.util.BitSet optionals = new java.util.BitSet();
      if (struct.isSetQuerySource()) {
        optionals.set(0);
      }
      if (struct.isSetPinotQuery()) {
        optionals.set(1);
      }
      oprot.writeBitSet(optionals, 2);
      if (struct.isSetQuerySource()) {
        struct.querySource.write(oprot);
      }
      if (struct.isSetPinotQuery()) {
        struct.pinotQuery.write(oprot);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, BrokerRequest struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
      java.util.BitSet incoming = iprot.readBitSet(2);
      if (incoming.get(0)) {
        struct.querySource = new QuerySource();
        struct.querySource.read(iprot);
        struct.setQuerySourceIsSet(true);
      }
      if (incoming.get(1)) {
        struct.pinotQuery = new org.apache.pinot.common.request.PinotQuery();
        struct.pinotQuery.read(iprot);
        struct.setPinotQueryIsSet(true);
      }
    }
  }

  private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
    return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
  }
}

